
#include "stdafx.h"
#include <myMysql.h>

namespace myFn
{
	namespace v1
	{
		
#define ______rs_to_num(cls,t,fn,...)	\
	stdsize cls::Get(stdsize index,t &out)	\
		{	\
		cchar *s = Get(index);	\
		if (s == nullptr)	\
		{	\
		return myFn::npos; \
	} \
	if (s[0] == 0)	\
		{	\
		return 0; \
	} \
	out = (t)::fn(s,__VA_ARGS__); \
	return 1; \
	}
#define  _____rs_to_ret_num(cls,t,nm)		\
	t cls::Get##nm##Num(stdsize index,t ifErrOrNull_ret)	\
		{ \
		t v; \
		stdsize res = Get(index,v); \
		if (res != 1) \
		{ \
		return ifErrOrNull_ret; \
	} \
	return v; \
	}

		/***********************************************************************
		.	myMysqlRs
		*************************************************************************/
		//[0]

		//[1]
		
		//[2]
		stdsize myMysqlRs::Get(stdsize index,char *out_str,stdsize out_str_size)
		{
			cchar *c2 = Get(index);
			if (c2 == nullptr)
			{
				return myFn::npos;
			}
			return strCpy(out_str,c2,out_str_size);
		}
		stdsize myMysqlRs::Get(stdsize index,wchar *out_str,stdsize out_str_size)
		{
			cchar *c2 = Get(index);
			if (c2 == nullptr)
			{
				return myFn::npos;
			}
			return strCpy(out_str,c2,out_str_size);
		}
		
		//[3]
		______rs_to_num(myMysqlRs,INT8		,atoi);
		______rs_to_num(myMysqlRs,INT16		,atoi);
		______rs_to_num(myMysqlRs,INT32		,atoi);
		______rs_to_num(myMysqlRs,INT64		,atoll);

		______rs_to_num(myMysqlRs,UINT8		,strtoul,nullptr,10);
		______rs_to_num(myMysqlRs,UINT16	,strtoul,nullptr,10);
		______rs_to_num(myMysqlRs,UINT32	,strtoul,nullptr,10);
		______rs_to_num(myMysqlRs,UINT64	,atoll);

		______rs_to_num(myMysqlRs,float		,atof);
		______rs_to_num(myMysqlRs,double	,strtod,nullptr);

		stdsize myMysqlRs::Get(stdsize index,stdwstring &out)
		{
			if (cchar *s = Get(index))
			{
				strCpy(out,s);
				return s[0]==0?0:1;
			}
			return myFn::npos;
		}
		stdsize myMysqlRs::Get(stdsize index,stdstring &out)
		{
			if (cchar *s = Get(index))
			{
				strCpy(out,s);
				return s[0]==0?0:1;
			}
			return myFn::npos;
		}


		//[4]

		_____rs_to_ret_num(myMysqlRs,INT8	,Char);
		_____rs_to_ret_num(myMysqlRs,INT16	,Short);
		_____rs_to_ret_num(myMysqlRs,INT32	,Int32);
		_____rs_to_ret_num(myMysqlRs,INT64	,Int64);
		_____rs_to_ret_num(myMysqlRs,UINT8	,UChar);
		_____rs_to_ret_num(myMysqlRs,UINT16	,UShort);
		_____rs_to_ret_num(myMysqlRs,UINT32	,UInt32);
		_____rs_to_ret_num(myMysqlRs,UINT64	,UInt64);

		_____rs_to_ret_num(myMysqlRs,stdssize	,Signed);
		_____rs_to_ret_num(myMysqlRs,stdsize	,Unsigned);
		_____rs_to_ret_num(myMysqlRs,float	,Float);
		_____rs_to_ret_num(myMysqlRs,double	,Double);
























		/***********************************************************************
		.	myMysqlRecord
		*************************************************************************/

		//field2index
		stdsize myMysqlRecord::__Field2Index(cchar *s) const
		{
			if (_rs == nullptr)
			{
				return -1;
			}
			return _rs->__Field2Index(s);
		}

		//[0]
		cchar *myMysqlRecord::Get(stdsize index)
		{
			if (_rs == nullptr)
			{
				return nullptr;
			}
			if (index>=0 && index < _rs->fieldCount())
			{
				return ((char**)__rowptr)[index];
			}
			return nullptr;
		}

		//[1]

		//[2]
		stdsize myMysqlRecord::Get(stdsize index,char *out_str,stdsize out_str_size)
		{
			cchar *c2 = Get(index);
			if (c2 == nullptr)
			{
				return myFn::npos;
			}
			return strCpy(out_str,c2,out_str_size);
		}
		stdsize myMysqlRecord::Get(stdsize index,wchar *out_str,stdsize out_str_size)
		{
			cchar *c2 = Get(index);
			if (c2 == nullptr)
			{
				return myFn::npos;
			}
			return strCpy(out_str,c2,out_str_size);
		}

		//[3]

		______rs_to_num(myMysqlRecord,INT8		,atoi);
		______rs_to_num(myMysqlRecord,INT16		,atoi);
		______rs_to_num(myMysqlRecord,INT32		,atoi);
		______rs_to_num(myMysqlRecord,INT64		,atoll);

		______rs_to_num(myMysqlRecord,UINT8		,strtoul,nullptr,10);
		______rs_to_num(myMysqlRecord,UINT16	,strtoul,nullptr,10);
		______rs_to_num(myMysqlRecord,UINT32	,strtoul,nullptr,10);
		______rs_to_num(myMysqlRecord,UINT64	,atoll);

		______rs_to_num(myMysqlRecord,float		,atof);
		______rs_to_num(myMysqlRecord,double	,strtod,nullptr);

		stdsize myMysqlRecord::Get(stdsize index,stdwstring &out)
		{
			if (cchar *s = Get(index))
			{
				strCpy(out,s);
				return s[0]==0?0:1;
			}
			return myFn::npos;
		}
		stdsize myMysqlRecord::Get(stdsize index,stdstring &out)
		{
			if (cchar *s = Get(index))
			{
				strCpy(out,s);
				return s[0]==0?0:1;
			}
			return myFn::npos;
		}


		//[4]

		_____rs_to_ret_num(myMysqlRecord,INT8	,Char);
		_____rs_to_ret_num(myMysqlRecord,INT16	,Short);
		_____rs_to_ret_num(myMysqlRecord,INT32	,Int32);
		_____rs_to_ret_num(myMysqlRecord,INT64	,Int64);
		_____rs_to_ret_num(myMysqlRecord,UINT8	,UChar);
		_____rs_to_ret_num(myMysqlRecord,UINT16	,UShort);
		_____rs_to_ret_num(myMysqlRecord,UINT32	,UInt32);
		_____rs_to_ret_num(myMysqlRecord,UINT64	,UInt64);

		_____rs_to_ret_num(myMysqlRecord,stdssize	,Signed);
		_____rs_to_ret_num(myMysqlRecord,stdsize	,Unsigned);
		_____rs_to_ret_num(myMysqlRecord,float	,Float);
		_____rs_to_ret_num(myMysqlRecord,double	,Double);



	};//v1
};//myFn